package com.example.mytayunapi.Controller;

import com.example.mytayunapi.Entity.publicInfo;
import com.example.mytayunapi.Entity.userInfo;
import com.example.mytayunapi.Service.publicInfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("public")
public class publicController {

    //分页
    //
    @GetMapping("/page")
    public PageInfo<publicInfo> pageInfo(@RequestParam Integer page, @RequestParam Integer size){
        return publicinfoService.getPageInfo(page,size);
    }


    @Autowired
    private publicInfoService publicinfoService;


    //http://localhost:8080/public/insert
    @PostMapping("/insert")
    public Integer insert( publicInfo publicinfo) {
        return publicinfoService.InsertPublicInfo(publicinfo);
    }

    //http://localhost:8080/public/query
    @GetMapping("/query")
    public List<publicInfo> query(String Public_title) {
        if(Public_title == null || Public_title.isEmpty()){
            return publicinfoService.getPublicInfo();
        }else {
            return publicinfoService.GetPublicInfo(Public_title);
        }
    }

    //http://localhost:8080/public/select
    @GetMapping("/select")
    public List<publicInfo> select() {
        return publicinfoService.getPublicInfo();
    }

    //http://localhost:8080/public/del
    @GetMapping("del/{Public_title}")
    public Integer del(@PathVariable String Public_title) {
        return publicinfoService.DeletePublicInfo(Public_title);
    }

    //http://localhost:8080/public/update
    @PostMapping("update")
    public Integer update(@RequestBody publicInfo publicinfo) {
        
        return publicinfoService.UpdatePublicInfo(publicinfo);
    }






}
